﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Forms;
using WpfLib.Craft;

namespace WinApp
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent(); 
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
           
        }

        private CraftUc _CraftUc;

        private void btnTest_Click(object sender, EventArgs e)
        {
            _CraftUc = new WpfLib.Craft.CraftUc();
            this.wpfHost.Child = _CraftUc;
            _CraftUc.InitCanvas(this.Width, this.Height);
            _CraftUc.AddPart("1", "test1");
            _CraftUc.AddPart("1.1", "test1.1", "1");
            _CraftUc.AddPart("1.2", "test1.2", "1");
            _CraftUc.AddPart("1.1.1", "test1.1.1", "1.1");
            _CraftUc.AddPart("1.2.1", "test1.2.1", "1.2");
            _CraftUc.AddPart("1.2.2", "test1.2.2", "1.2");
            _CraftUc.ShowPartInfo += ucCraft_ShowPartInfo;
        }

        void ucCraft_ShowPartInfo(object sender, EventArgs e)
        {
            PartUc part = sender as PartUc;
            MessageBox.Show("你要打开部件:"+part.PartId);
            part.Title += "已打开";
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder(1000);
            foreach (string partId in _CraftUc.Parts.Keys)
            {
                sb.AppendLine("*******************");
                PartUc part = _CraftUc.Parts[partId];
                sb.AppendLine("Id: " + partId );
                sb.AppendLine("Title: " + part.Title);
                sb.AppendLine("X: " + part.X);
                sb.AppendLine("Y: " + part.Y);
                sb.AppendLine();
                
            }

            MessageBox.Show(sb.ToString());
        }
    }
}
